package com.ruoyi.eamp.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.eamp.domain.EampEmail;
import com.ruoyi.eamp.domain.EampEmailUser;
import com.ruoyi.eamp.domain.vo.EmailAndUserVO;
import com.ruoyi.eamp.mapper.EampEmailMapper;
import com.ruoyi.eamp.mapper.EampEmailUserMapper;
import com.ruoyi.eamp.service.IEampEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 邮件信息表Service业务层处理
 * 
 * @author 吴
 * @date 2024-08-07
 */
@Service
public class EampEmailServiceImpl implements IEampEmailService
{
    @Autowired
    private EampEmailMapper eampEmailMapper;
    @Autowired
    private EampEmailUserMapper eampEmailUserMapper;

    /**
     * 查询邮件信息表
     * 
     * @param emailAndUserVO 邮件信息表主键
     * @return 邮件信息表
     */
    @Override
    public EmailAndUserVO selectEampEmailByEmailId(EmailAndUserVO emailAndUserVO)
    {
        return eampEmailMapper.selectEampEmailByEmailId(emailAndUserVO);
    }

    /**
     * 查询邮件信息表列表
     * 
     * @param eampEmail 邮件信息表
     * @return 邮件信息表
     */
    @Override
    public List<EampEmail> selectEampEmailList(EampEmail eampEmail)
    {
        return eampEmailMapper.selectEampEmailList(eampEmail);
    }

    /**
     * 新增邮件信息表
     * 
     * @param
     * @return 结果
     */
    @Override
    public int insertEampEmail(EmailAndUserVO emailAndUserVO)
    {
        emailAndUserVO.setCreateTime(DateUtils.getNowDate());
        return eampEmailMapper.insertEampEmail(emailAndUserVO);
    }

    /**
     * 修改邮件信息表
     * 
     * @param emailAndUserVO 邮件信息表
     * @return 结果
     */
    @Override
    public int updateEampEmail(EmailAndUserVO emailAndUserVO)
    {
        return eampEmailMapper.updateEampEmail(emailAndUserVO);
    }

    /**
     * 批量删除邮件信息表
     * 
     * @param emailIds 需要删除的邮件信息表主键
     * @return 结果
     */
    @Override
    public int deleteEampEmailByEmailIds(Long[] emailIds,Long userId)
    {
        return eampEmailMapper.deleteEampEmailByEmailIds(emailIds,userId);
    }

    /**
     * 删除邮件信息表信息
     * 
     * @param emailId 邮件信息表主键
     * @return 结果
     */
    @Override
    public int deleteEampEmailByEmailId(Long emailId)
    {
        return eampEmailMapper.deleteEampEmailByEmailId(emailId);
    }

    @Override
    public List<EmailAndUserVO> selectEmailAndUserAll(EmailAndUserVO emailAndUserVO) {
        return eampEmailMapper.selectEmailAndUserAll(emailAndUserVO);
    }

    @Override
    public List<SysUser> allUserEmailList(Long userId) {
        return eampEmailMapper.allUserEmailList(userId);
    }

    @Override
    public int insertEampEmailUser(EmailAndUserVO emailAndUserVO) {
        EampEmailUser eampEmailUser = new EampEmailUser(emailAndUserVO.getConsigneeId(),emailAndUserVO.getEmailId(),2l,2l,0l,1l);
        eampEmailUserMapper.insertEampEmailUser(eampEmailUser);
        eampEmailUser.setUserId(emailAndUserVO.getAddresserId());
        eampEmailUser.setConnection(1l);
        eampEmailUser.setStatus(null);
        eampEmailUser.setEmailGenre(2l);
        return  eampEmailUserMapper.insertEampEmailUser(eampEmailUser);
    }

    @Override
    public int saveEampEmailUser(EmailAndUserVO emailAndUserVO) {
        EampEmailUser eampEmailUser =
        new EampEmailUser(emailAndUserVO.getAddresserId(),emailAndUserVO.getEmailId(),1l,null,0l,emailAndUserVO.getEmailGenre());
        return  eampEmailUserMapper.insertEampEmailUser(eampEmailUser);
    }

    @Override
    public int deleteRealEampEmailByEmailIds(Long[] emailIds, Long userId) {
        return  eampEmailMapper.deleteRealEampEmailByEmailIds(emailIds,userId);
    }

    @Override
    public int sendEampEmailUser(EmailAndUserVO emailAndUserVO) {
        eampEmailMapper.updateEampEmailUser(emailAndUserVO);
        eampEmailMapper.updateEampEmail(emailAndUserVO);
        EampEmailUser eampEmailUser = new EampEmailUser(emailAndUserVO.getConsigneeId(),emailAndUserVO.getEmailId(),2l,2l,0l,1l);
        return eampEmailUserMapper.insertEampEmailUser(eampEmailUser);
    }

    @Override
    public int updateStatus(Long ueId) {
        return eampEmailMapper.updateStatus(ueId);
    }

    @Override
    public int restoreGenre(Long ueId) {
        return eampEmailMapper.restoreGenre(ueId);
    }

    @Override
    public List<EmailAndUserVO> getListBing(EmailAndUserVO emailAndUserVO) {
        return eampEmailMapper.getListBing(emailAndUserVO);
    }

}
